package enumandlambda;

import java.time.LocalDateTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author shkstart
 * @create 2022-12-08-14:29
 */
public class ThreadPoolDemo6 {
    public static void main(String[] args) {
        //单线程执行定时任务的线程池
        ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
        System.out.println("添加任务的时间："+ LocalDateTime.now());
        service.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行任务："+LocalDateTime.now());
            }
        },2, TimeUnit.SECONDS);

    }
}
